<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>编辑用户</title>
    <style>
        body {
            background: #f8f1f4;
            font-family: 'Orbitron', sans-serif;
            color: #333;
        }
        .card {
            max-width: 500px;
            margin: 60px auto;
            padding: 30px;
            background: linear-gradient(145deg, #ffffff, #f5e8ee);
            border: 2px solid #ff6b9d;
            border-radius: 12px;
            box-shadow: 0 0 20px #ff6b9d;
        }
        h2 {
            text-align: center;
            margin-bottom: 20px;
            color: #ff6b9d;
            text-shadow: 0 0 5px #ff6b9d;
        }
        label {
            display: block;
            margin: 12px 0 6px;
        }
        input, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ff6b9d;
            background: #fff5f8;
            color: #333;
            border-radius: 6px;
            font-size: 14px;
        }
        .btn-group {
            text-align: center;
            margin-top: 20px;
        }
        .btn {
            background: transparent;
            border: 2px solid #ff6b9d;
            color: #ff6b9d;
            padding: 10px 25px;
            margin: 0 10px;
            border-radius: 6px;
            cursor: pointer;
            transition: 0.3s;
        }
        .btn:hover {
            background: #ff6b9d;
            color: #fff;
        }
    </style>
    <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@500&display=swap" rel="stylesheet">
</head>
<body>
<div class="card">
    <h2>编辑用户</h2>
    <form action="${pageContext.request.contextPath}/user/update" method="post" onsubmit="return validateForm()">
        <input type="hidden" name="uid" value="${user.uid}">

        <label>用户名</label>
        <input type="text" name="uname" id="uname" value="${user.uname}" required>

        <label>密码</label>
        <input type="password" name="pwd" id="pwd" value="${user.pwd}" required>

        <label>邮箱</label>
        <input type="email" name="email" id="email" value="${user.email}">

        <label>用户类型</label>
        <select name="type" required>
            <option value="普通用户" ${user.type == '普通用户' ? 'selected' : ''}>普通用户</option>
        </select>

        <label>激活状态</label>
        <select name="active" required>
            <option value="1" ${user.active == 1 ? 'selected' : ''}>激活</option>
            <option value="0" ${user.active == 0 ? 'selected' : ''}>未激活</option>
        </select>

        <div class="btn-group">
            <input type="submit" class="btn" value="提交">
            <input type="button" class="btn" value="取消" onclick="window.location.href='${pageContext.request.contextPath}/user/list'">
        </div>
    </form>
</div>

<script>
    function validateForm() {
        const uname = document.getElementById("uname").value.trim();
        const pwd = document.getElementById("pwd").value;
        const email = document.getElementById("email").value.trim();

        if (uname.length === 0) {
            alert("用户名不能为空！");
            return false;
        }
        if (pwd.length < 6) {
            alert("密码长度至少为 6 位！");
            return false;
        }
        if (email.length > 0 && !/^[\w.-]+@[\w.-]+\.\w+$/.test(email)) {
            alert("邮箱格式不正确！");
            return false;
        }

        return true;
    }
</script>
</body>
</html>